<?php

define('IN_DOUCO', true);

// 强制在移动端中显示PC版
if (isset($_REQUEST['mobile'])) {
   setcookie('client', 'pc');
   if ($_COOKIE['client'] != 'pc') $_COOKIE['client'] = 'pc';
}

require (dirname(__FILE__) . '/include/init.php');

if ($_REQUEST['lang']) {
    $lang = $_REQUEST['lang'];
}else{
    $lang = 'zh';
}
require (dirname(__FILE__) . '/common.php');

$smarty->assign('dangqun_url', get_dangqun($lang));
$smarty->assign('zhaosheng_url', get_zhaosheng($lang));


// 赋值给模板-数据
$smarty->assign('show_list', $dou->get_show_list('pc', $lang));
$smarty->assign('links', get_link_list($lang));
$smarty->assign('yjjx_article_list', get_list('article', '8', $lang, 3, 'sort ASC, title'));
$smarty->assign('xwdt_article_list', get_list('article', '19', $lang, 3, 'sort ASC, title'));
$smarty->assign('xsbg_article_list', get_list('article', '21, 22, 23', $lang, 3, 'date DESC'));
$smarty->assign('tggg_article_list', get_list('article', '20', $lang, 6, 'sort ASC, title'));
$smarty->assign('yjfx_article_list', get_list('article', '7', $lang, 100, 'sort ASC, title'));
$smarty->assign('sysjj_article_list', get_list('article', '1', $lang, 5, 'sort ASC, title'));
$smarty->assign('lang', $lang);

$smarty->display('index.dwt');

/**
 * +----------------------------------------------------------
 * 获取友情链接
 * +----------------------------------------------------------
 */
function get_link_list($lang = '') {
    $sql = "SELECT * FROM " . $GLOBALS['dou']->table('link') . " WHERE lang='" . $lang . "' ORDER BY sort ASC, id ASC";
    $query = $GLOBALS['dou']->query($sql);
    while ($row = $GLOBALS['dou']->fetch_array($query)) {
        $link_list[] = array (
                "id" => $row['id'],
                "link_name" => $row['link_name'],
                "link_url" => $row['link_url'],
                "sort" => $row['sort']
        );
    }

    return $link_list;
}


function get_list($module, $cat_id = '', $lang = '', $num = '', $sort = '') {
    $where = ' WHERE cat_id IN (' . $cat_id . ') and lang=\''. $lang.'\'';
    $sort = $sort ? $sort : '';
    $limit = $num ? ' LIMIT ' . $num : '';
    
    $sql = "SELECT * FROM " . $GLOBALS['dou']->table($module) . $where . " ORDER BY " . $sort . $limit;
    $query = $GLOBALS['dou']->query($sql);
    while ($row = $GLOBALS['dou']->fetch_array($query)) {
        $item['id'] = $row['id'];
        if ($row['title']) $item['title'] = $row['title'];
        if ($row['name']) $item['name'] = $row['name'];
        if (!empty($row['price'])) $item['price'] = $row['price'] > 0 ? $GLOBALS['dou']->price_format($row['price']) : $GLOBALS['_LANG']['price_discuss'];
        if ($row['click']) $item['click'] = $row['click'];

        $item['add_time'] = date("Y-m-d", $row['add_time']);
        $item['add_time_short'] = date("m-d", $row['add_time']);
        $item['date'] = $row['date'];
        $item['description'] = $row['description'] ? $row['description'] : $GLOBALS['dou']->dou_substr($row['content'], 320, false);
        $item['image'] = $row['image'] ? ROOT_URL . $row['image'] : '';
        $image = explode(".", $row['image']);
        $item['thumb'] = ROOT_URL . $image[0] . "_thumb." . $image[1];
        if($cat_id=='7' || $cat_id=='8'){
            $item['url'] = $row['url'];
        }else{
            $item['url'] = 'info.php?id='.$row['id'].'&lang='.$row['lang'];            
        }

        
        $list[] = $item;
    }
    
    return $list;
}

?>
